import { getUserInfoUrl } from "@/command/apiTool";
import { useDetail } from "@/hooks";
import { useRoute } from "vue-router";
import { getAction } from "@/command/netTool";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;
export const useRequest = () => {
  const route = useRoute();
  const [detail, detailControl] = useDetail(
    getUserInfoUrl(
      {
        dh: "/api/H5/richCourse/small/getTrainDetail",
        xh: "/api/H5/richCourse/small/getTrainDetail",
      },
      { id: route.query.id || "" }
    ),
    {
      id: "",
      comment: "",
      time: "",
      status: "",
      title: "",
    }
  );

  const btnAction = (params: any) => {
    getAction(
      getUserInfoUrl({
        dh: "/api/H5/richCourse/large/join",
        xh: "/api/H5/richCourse/small/join",
      }).url,
      { ...params },
      { isResolve: true }
    ).then((e) => {
      console.log("eee", e);
      showSuccessToast(e.msg || e.data);
      // 刷新接口
      detailControl.refresh();
    });
  };

  return {
    detail,
    btnAction,
  };
};
